home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / essentls / DMusProd / data1.cab / FarmGameAppSrc / FARM.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-16  |  19.6 KB  |  633 lines

  1. //-----------------------------------------------------------------------------
  2. // File: Farm.cpp
  3. //
  4. // Desc: Plays a script file using DirectMusic
  5. //
  6. //@@BEGIN_MSINTERNAL
  7. //
  8. // Hist: 02.24.00 - forrest - Created from PlaySegment
  9. //
  10. //@@END_MSINTERNAL
  11. // Copyright (c) 2000 Microsoft Corporation. All rights reserved.
  12. //-----------------------------------------------------------------------------
  13. #define STRICT
  14. #include <windows.h>
  15. #include <basetsd.h>
  16. #include <commdlg.h>
  17. #include <objbase.h>
  18. #include <stdio.h>
  19. #include <dmusicc.h>
  20. #include <dmusici.h>
  21. #include <dxerr8.h>
  22. #include "resource.h"
  23. #include <tchar.h>
  24. #include "DMUtil.h"
  25. #include "DXUtil.h"
  26.  
  27.  
  28.  
  29.  
  30. //-----------------------------------------------------------------------------
  31. // Function-prototypes
  32. //-----------------------------------------------------------------------------
  33. INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam );
  34. HRESULT OnInitDialog( HWND hDlg );
  35. HRESULT OnChangeScriptFile( HWND hDlg, TCHAR* strFileName );
  36. HRESULT OnCallRoutine( HWND hDlg, TCHAR* strRoutine );
  37. HRESULT UpdateVariables( HWND hDlg );
  38. HRESULT SetVariable( HWND hDlg, int nIDDlgItem );
  39. void    DrawButton( int nDlgItem, HWND hDlgItem, LPDRAWITEMSTRUCT lpDrawItemStruct );
  40. void    DrawStatic( int nDlgItem, HWND hDlgItem, LPDRAWITEMSTRUCT lpDrawItemStruct );
  41. void    PlayButton( HWND hDlg, int nDlgItem );
  42. HRESULT ProcessDirectMusicMessages( HWND hDlg );
  43. BOOL    LoadBitmapFromResource( int nResourceID, HBITMAP *phBitmap, HPALETTE *phPalette );
  44. HRESULT CreateAudioPathFromFile( IDirectMusicAudioPath** ppAudioPath, TCHAR* strFileName );
  45.  
  46. #define ORANGE_COLOR        RGB(255, 130, 0)
  47. #define GREEN_COLOR         RGB(0, 195, 0)
  48. #define YELLOW_COLOR        RGB(198, 195, 0)
  49. #define LT_ORANGE_COLOR     RGB(255, 195, 132)
  50. #define LT_GREEN_COLOR      RGB(132, 255, 132)
  51. #define LT_YELLOW_COLOR     RGB(255, 255, 198)
  52. #define RED_COLOR           RGB(255, 0, 0)
  53. #define BACKGROUND_COLOR    RGB(198, 65, 0)
  54. #define BLACK_COLOR         RGB(0, 0, 0)
  55. #define WHITE_COLOR         RGB(255, 255, 255)
  56.  
  57.  
  58.  
  59.  
  60. //-----------------------------------------------------------------------------
  61. // Defines, constants, and global variables
  62. //-----------------------------------------------------------------------------
  63. #define NUM_PLAY_BUTTONS (IDC_ALARM - IDC_BIRD + 1)
  64.  
  65. CMusicManager* g_pMusicManager      = NULL;
  66. CMusicScript*  g_pMusicScript       = NULL;
  67. IDirectMusicAudioPath* g_pFarmAudioPath = NULL;
  68. HINSTANCE      g_hInst              = NULL;
  69. HBRUSH         g_hOrangeBrush       = NULL;
  70. HBRUSH         g_hGreenBrush        = NULL;
  71. HBRUSH         g_hYellowBrush       = NULL;
  72. HBRUSH         g_hLtOrangeBrush     = NULL;
  73. HBRUSH         g_hLtGreenBrush      = NULL;
  74. HBRUSH         g_hLtYellowBrush     = NULL;
  75. HBRUSH         g_hBackgroundBrush   = NULL;
  76. HBRUSH         g_hRedBrush          = NULL;
  77. BOOL           g_bButtonPlaying[ NUM_PLAY_BUTTONS ];
  78. HBITMAP        g_hBitmap            = NULL;
  79. HPALETTE       g_hPalette           = NULL;
  80.  
  81.  
  82.  
  83.  
  84.  
  85. //-----------------------------------------------------------------------------
  86. // Name: WinMain()
  87. // Desc: Entry point for the application.  Since we use a simple dialog for 
  88. //       user interaction we don't need to pump messages.
  89. //-----------------------------------------------------------------------------
  90. INT APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, 
  91.                       INT nCmdShow )
  92. {
  93.     HWND    hDlg = NULL;
  94.     BOOL    bDone = FALSE;
  95.     int     nExitCode;
  96.     MSG     msg;
  97.  
  98.     g_hInst = hInst;
  99.     ZeroMemory( g_bButtonPlaying, sizeof(BOOL)*NUM_PLAY_BUTTONS );
  100.  
  101.     // Display the main dialog box.
  102.     hDlg = CreateDialog( hInst, MAKEINTRESOURCE(IDD_MAIN), 
  103.                          NULL, MainDlgProc );
  104.  
  105.     while( !bDone ) 
  106.     { 
  107.         // Windows messages are available
  108.         while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) 
  109.         { 
  110.             if( !IsDialogMessage( hDlg, &msg ) )  
  111.             {
  112.                 TranslateMessage( &msg ); 
  113.                 DispatchMessage( &msg ); 
  114.             }
  115.  
  116.             if( msg.message == WM_QUIT )
  117.             {
  118.                 nExitCode = (int)msg.wParam;
  119.                 bDone     = TRUE;
  120.                 DestroyWindow( hDlg );
  121.             }
  122.         }
  123.     }
  124.  
  125.     return nExitCode;
  126. }
  127.  
  128.  
  129.  
  130.  
  131. //-----------------------------------------------------------------------------
  132. // Name: MainDlgProc()
  133. // Desc: Handles dialog messages
  134. //-----------------------------------------------------------------------------
  135. INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
  136. {
  137.     HRESULT hr;
  138.  
  139.     switch( msg ) 
  140.     {
  141.         case WM_INITDIALOG:
  142.             if( FAILED( hr = OnInitDialog( hDlg ) ) )
  143.             {
  144.                 DXTRACE_ERR( TEXT("OnInitDialog"), hr );
  145.                 MessageBox( hDlg, "Error initializing DirectMusic.  Sample will now exit.", 
  146.                                   "DirectMusic Sample", MB_OK | MB_ICONERROR );
  147.                 PostQuitMessage( IDCANCEL );
  148.                 return TRUE;
  149.             }
  150.             break;
  151.  
  152.         case WM_PAINT:
  153.         {
  154.             PAINTSTRUCT   ps;
  155.             HBITMAP       hOldBitmap;
  156.             HPALETTE      hOldPalette;
  157.             HDC           hDC, hMemDC;
  158.             BITMAP        bm;
  159.  
  160.             hDC = BeginPaint( hDlg, &ps );
  161.  
  162.             if( g_hBitmap )
  163.             {
  164.                 GetObject( g_hBitmap, sizeof(BITMAP), &bm );
  165.                 hMemDC = CreateCompatibleDC( hDC );
  166.                 hOldBitmap = (HBITMAP)SelectObject( hMemDC, g_hBitmap );
  167.                 hOldPalette = SelectPalette( hDC, g_hPalette, FALSE );
  168.                 RealizePalette( hDC );
  169.  
  170.                 BitBlt( hDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY );
  171.  
  172.                 SelectObject( hMemDC, hOldBitmap );
  173.                 SelectPalette( hDC, hOldPalette, FALSE );
  174.             }
  175.  
  176.             EndPaint( hDlg, &ps );
  177.             break;
  178.         }
  179.  
  180.         case WM_DRAWITEM:
  181.             switch( ((LPDRAWITEMSTRUCT) lParam)->CtlType )
  182.             {
  183.             case ODT_BUTTON:
  184.                 DrawButton( wParam, GetDlgItem(hDlg, wParam), (LPDRAWITEMSTRUCT) lParam );
  185.                 break;
  186.  
  187.             case ODT_STATIC:
  188.                 DrawStatic( wParam, GetDlgItem(hDlg, wParam), (LPDRAWITEMSTRUCT) lParam );
  189.                 break;
  190.  
  191.             default:
  192.                 return FALSE;
  193.             }
  194.  
  195.             return TRUE;
  196.             break;
  197.  
  198.         case WM_COMMAND:
  199.             switch( LOWORD(wParam) )
  200.             {
  201.                 case IDC_ALLSTOP:
  202.                 case IDC_BIRD:
  203.                 case IDC_NIGHT:
  204.                 case IDC_PREDAWN:
  205.                 case IDC_DAWN:
  206.                 case IDC_END:
  207.                 case IDC_COUGAR:
  208.                 case IDC_COW:
  209.                 case IDC_ROOSTER:
  210.                 case IDC_SHEEP:
  211.                 case IDC_WOLF:
  212.                 case IDC_ALARM:
  213.                 {
  214.                     PlayButton( hDlg, LOWORD(wParam) );
  215.                     break;
  216.                 }
  217.  
  218.                 case IDCANCEL:
  219.                 {
  220.                     PostQuitMessage( IDCANCEL );
  221.                     break;
  222.                 }
  223.  
  224.                 default:
  225.                 {
  226.                     return FALSE; // Didn't handle message
  227.                 }
  228.             }
  229.             break;
  230.  
  231.         case WM_DESTROY:
  232.             // Cleanup everything
  233.             SAFE_RELEASE( g_pFarmAudioPath );
  234.             SAFE_DELETE( g_pMusicScript );
  235.             SAFE_DELETE( g_pMusicManager );
  236.  
  237.             DeleteObject( g_hOrangeBrush );
  238.             DeleteObject( g_hGreenBrush );
  239.             DeleteObject( g_hYellowBrush );
  240.             DeleteObject( g_hLtOrangeBrush );
  241.             DeleteObject( g_hLtGreenBrush );
  242.             DeleteObject( g_hLtYellowBrush );
  243.             DeleteObject( g_hRedBrush );
  244.             DeleteObject( g_hBackgroundBrush );
  245.             DeleteObject( g_hBitmap );
  246.             DeleteObject( g_hPalette );
  247.  
  248.             break; 
  249.  
  250.         default:
  251.             return FALSE; // Didn't handle message
  252.     }
  253.  
  254.     return TRUE; // Handled message
  255. }
  256.  
  257.  
  258.  
  259.  
  260. //-----------------------------------------------------------------------------
  261. // Name: OnInitDialog()
  262. // Desc: Initializes the dialogs (sets up UI controls, etc.)
  263. //-----------------------------------------------------------------------------
  264. HRESULT OnInitDialog( HWND hDlg )
  265. {
  266.     HRESULT hr;
  267.  
  268.     // Load the icon
  269.     HICON hIcon = LoadIcon( g_hInst, MAKEINTRESOURCE( IDR_MAINFRAME ) );
  270.  
  271.     // Set the icon for this dialog.
  272.     SendMessage( hDlg, WM_SETICON, ICON_BIG,   (LPARAM) hIcon );  // Set big icon
  273.     SendMessage( hDlg, WM_SETICON, ICON_SMALL, (LPARAM) hIcon );  // Set small icon
  274.  
  275.     g_hOrangeBrush    = CreateSolidBrush(ORANGE_COLOR);
  276.     g_hGreenBrush     = CreateSolidBrush(GREEN_COLOR);
  277.     g_hYellowBrush    = CreateSolidBrush(YELLOW_COLOR);
  278.     g_hLtOrangeBrush  = CreateSolidBrush(LT_ORANGE_COLOR);
  279.     g_hLtGreenBrush   = CreateSolidBrush(LT_GREEN_COLOR);
  280.     g_hLtYellowBrush  = CreateSolidBrush(LT_YELLOW_COLOR);
  281.     g_hRedBrush       = CreateSolidBrush(RED_COLOR);
  282.     g_hBackgroundBrush= CreateSolidBrush(BACKGROUND_COLOR);
  283.  
  284.     g_pMusicManager = new CMusicManager();
  285.  
  286.     if( FAILED( hr = g_pMusicManager->Initialize( hDlg ) ) )
  287.         return hr;
  288.  
  289.     // Free any previous script, and make a new one
  290.     SAFE_DELETE( g_pMusicScript );
  291.  
  292.     // Have the loader collect any garbage now that the old 
  293.     // script has been released
  294.     g_pMusicManager->CollectGarbage();
  295.  
  296.     // Set the default media path (something like C:\MSSDK\SAMPLES\MULTIMEDIA\MEDIA)
  297.     // to be used as the search directory for finding DirectMusic content.
  298.     TCHAR strPath[MAX_PATH];
  299.  
  300.     GetCurrentDirectory( MAX_PATH, strPath );
  301.     lstrcat( strPath, TEXT("\\res") );
  302.     g_pMusicManager->SetSearchDirectory( strPath );
  303.  
  304.     // Load the script file
  305.     if( FAILED( hr = g_pMusicManager->CreateScriptFromFile( &g_pMusicScript, "farmmusic.spt" ) ) )
  306.     {
  307.         GetCurrentDirectory( MAX_PATH, strPath );
  308.         lstrcat( strPath, TEXT("\\..\\res") );
  309.         g_pMusicManager->SetSearchDirectory( strPath );
  310.  
  311.         if( FAILED( hr = g_pMusicManager->CreateScriptFromFile( &g_pMusicScript, "farmmusic.spt" ) ) )
  312.             return DXTRACE_ERR( TEXT("CreateScriptFromFile"), hr );
  313.     }
  314.  
  315.     LoadBitmapFromResource( IDB_BITMAP1, &g_hBitmap, &g_hPalette );
  316.  
  317.     return S_OK;
  318. }
  319.  
  320.  
  321.  
  322.  
  323. //-----------------------------------------------------------------------------
  324. // Name: OnCallRoutine()
  325. // Desc: 
  326. //-----------------------------------------------------------------------------
  327. HRESULT OnCallRoutine( HWND hDlg, TCHAR* strRoutine )
  328. {
  329.     HRESULT hr;
  330.  
  331.     if( FAILED( hr = g_pMusicScript->CallRoutine( strRoutine ) ) )
  332.         return DXTRACE_ERR( TEXT("CallRoutine"), hr );
  333.  
  334.     return S_OK;
  335. }
  336.  
  337.  
  338.  
  339.  
  340. //-----------------------------------------------------------------------------
  341. // Name: DrawButton()
  342. // Desc: 
  343. //-----------------------------------------------------------------------------
  344. void DrawButton( int nDlgItem, HWND hDlgItem, LPDRAWITEMSTRUCT lpDrawItemStruct )  
  345. {
  346.     TCHAR strText[MAX_PATH];
  347.     UINT uStyle = DFCS_BUTTONPUSH;
  348.     COLORREF crBkColor;
  349.     HBRUSH* phBrush = NULL;
  350.     int nIndex = nDlgItem - IDC_BIRD;
  351.     
  352.     // If drawing selected, add the pushed style to DrawFrameControl.
  353.     if (lpDrawItemStruct->itemState & ODS_SELECTED)
  354.         uStyle |= DFCS_PUSHED;
  355.     
  356.     switch( nDlgItem )
  357.     {
  358.         case IDCANCEL:
  359.         case IDC_ALLSTOP:
  360.         {
  361.             phBrush = &g_hRedBrush;
  362.             crBkColor = RED_COLOR;
  363.             break;
  364.         }
  365.  
  366.         case IDC_BIRD:
  367.         {
  368.             if( g_bButtonPlaying[nIndex] )
  369.             {
  370.                 phBrush = &g_hLtYellowBrush;
  371.                 crBkColor = LT_YELLOW_COLOR;
  372.             }
  373.             else
  374.             {
  375.                 phBrush = &g_hYellowBrush;
  376.                 crBkColor = YELLOW_COLOR;
  377.             }
  378.             break;
  379.         }
  380.  
  381.         case IDC_NIGHT:
  382.         case IDC_PREDAWN:
  383.         case IDC_DAWN:
  384.         case IDC_END:
  385.         {
  386.             if( g_bButtonPlaying[nIndex] )
  387.             {
  388.                 phBrush = &g_hLtGreenBrush;
  389.                 crBkColor = LT_GREEN_COLOR;
  390.             }
  391.             else
  392.             {
  393.                 phBrush = &g_hGreenBrush;
  394.                 crBkColor = GREEN_COLOR;
  395.             }
  396.             break;
  397.         }
  398.  
  399.         case IDC_COUGAR:
  400.         case IDC_COW:
  401.         case IDC_ROOSTER:
  402.         case IDC_SHEEP:
  403.         case IDC_WOLF:
  404.         case IDC_ALARM:
  405.         {
  406.             if( g_bButtonPlaying[nIndex] )
  407.             {
  408.                 phBrush = &g_hLtOrangeBrush;
  409.                 crBkColor = LT_ORANGE_COLOR;
  410.             }
  411.             else
  412.             {
  413.                 phBrush = &g_hOrangeBrush;
  414.                 crBkColor = ORANGE_COLOR;
  415.             }
  416.             break;
  417.         }
  418.     }
  419.  
  420.     SetTextColor( lpDrawItemStruct->hDC, BLACK_COLOR );
  421.     SetBkColor( lpDrawItemStruct->hDC, crBkColor );
  422.     SelectObject( lpDrawItemStruct->hDC, *phBrush );
  423.  
  424.     // Draw the button frame.
  425.     DrawFrameControl( lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem, 
  426.         DFC_BUTTON, uStyle );
  427.  
  428.     // Fill center with new color
  429.     RECT rc = lpDrawItemStruct->rcItem;
  430.     rc.left     += 2;
  431.     rc.top      += 2;
  432.     rc.bottom   -= 2;
  433.     rc.right    -= 2;
  434.     FillRect( lpDrawItemStruct->hDC, &rc, *phBrush );
  435.  
  436.     // Draw text
  437.     GetWindowText( hDlgItem, strText, MAX_PATH );
  438.     DrawText( lpDrawItemStruct->hDC, strText, _tcslen(strText), 
  439.               &lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER );
  440. }
  441.  
  442.  
  443.  
  444.  
  445. //-----------------------------------------------------------------------------
  446. // Name: DrawStatic()
  447. // Desc: 
  448. //-----------------------------------------------------------------------------
  449. void DrawStatic( int nDlgItem, HWND hDlgItem, LPDRAWITEMSTRUCT lpDrawItemStruct )  
  450. {
  451.     SetTextColor( lpDrawItemStruct->hDC, WHITE_COLOR );
  452.     SetBkMode( lpDrawItemStruct->hDC, TRANSPARENT );
  453.  
  454.     // Draw text
  455.     TCHAR strText[MAX_PATH];
  456.     GetWindowText( hDlgItem, strText, MAX_PATH );
  457.     DrawText( lpDrawItemStruct->hDC, strText, _tcslen(strText), 
  458.               &lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER );
  459.  
  460.     SetBkMode( lpDrawItemStruct->hDC, OPAQUE );
  461. }
  462.  
  463.  
  464.  
  465.  
  466. //-----------------------------------------------------------------------------
  467. // Name: PlayButton()
  468. // Desc: 
  469. //-----------------------------------------------------------------------------
  470. void PlayButton( HWND hDlg, int nDlgItem )
  471. {
  472.     int nIndex = nDlgItem - IDC_BIRD;
  473.     switch( nDlgItem )
  474.     {       
  475.         case IDC_ALLSTOP:
  476.             g_pMusicScript->CallRoutine( TEXT("dmAllStop") );
  477.             break;
  478.  
  479.         case IDC_BIRD:
  480.             g_pMusicScript->CallRoutine( TEXT("dmSSBird") );
  481.             break;
  482.  
  483.         case IDC_NIGHT:
  484.             g_pMusicScript->CallRoutine( TEXT("dmBGNight") );
  485.             break;
  486.  
  487.         case IDC_PREDAWN:
  488.             g_pMusicScript->CallRoutine( TEXT("dmBGPredawn") );
  489.             break;
  490.  
  491.         case IDC_DAWN:
  492.             g_pMusicScript->CallRoutine( TEXT("dmBGDawn") );
  493.             break;
  494.  
  495.         case IDC_END:
  496.             g_pMusicScript->CallRoutine( TEXT("dmEnding") );
  497.             break;
  498.  
  499.         case IDC_COUGAR:
  500.             g_pMusicScript->CallRoutine( TEXT("dmSfxCougar") );
  501.             break;
  502.  
  503.         case IDC_COW:
  504.             g_pMusicScript->CallRoutine( TEXT("dmSfxCow") );
  505.             break;
  506.  
  507.         case IDC_ROOSTER:
  508.             g_pMusicScript->CallRoutine( TEXT("dmSfxRooster") );
  509.             break;
  510.  
  511.         case IDC_SHEEP:
  512.             g_pMusicScript->CallRoutine( TEXT("dmSfxSheep") );
  513.             break;
  514.  
  515.         case IDC_WOLF:            
  516.             g_pMusicScript->CallRoutine( TEXT("dmSfxWolf") );
  517.             break;
  518.  
  519.         case IDC_ALARM:
  520.             g_pMusicScript->CallRoutine( TEXT("dmSfxAlarm") );
  521.             break;
  522.     }
  523.  
  524.     InvalidateRect( GetDlgItem( hDlg, nDlgItem ), NULL, TRUE );
  525. }
  526.  
  527.  
  528.  
  529.  
  530. //-----------------------------------------------------------------------------
  531. // Name: LoadBitmapFromResource()
  532. // Desc: 
  533. //-----------------------------------------------------------------------------
  534. BOOL LoadBitmapFromResource( int nResourceID, HBITMAP *phBitmap, HPALETTE *phPalette )
  535. {
  536.     
  537.     BITMAP  bm;
  538.     
  539.     *phBitmap = NULL;
  540.     *phPalette = NULL;
  541.     
  542.     // Use LoadImage() to get the image loaded into a DIBSection
  543.     *phBitmap = (HBITMAP)LoadImage( g_hInst, MAKEINTRESOURCE(nResourceID), IMAGE_BITMAP, 0, 0,
  544.                                     LR_CREATEDIBSECTION | LR_DEFAULTSIZE );
  545.     if( *phBitmap == NULL )
  546.         return FALSE;
  547.     
  548.     // Get the color depth of the DIBSection
  549.     GetObject(*phBitmap, sizeof(BITMAP), &bm );
  550.  
  551.     // If the DIBSection is 256 color or less, it has a color table
  552.     if( ( bm.bmBitsPixel * bm.bmPlanes ) <= 8 )
  553.     {
  554.         HDC           hMemDC;
  555.         HBITMAP       hOldBitmap;
  556.         RGBQUAD       rgb[256];
  557.         LPLOGPALETTE  pLogPal;
  558.         WORD          i;
  559.         
  560.         // Create a memory DC and select the DIBSection into it
  561.         hMemDC = CreateCompatibleDC( NULL );
  562.         hOldBitmap = (HBITMAP)SelectObject( hMemDC, *phBitmap );
  563.         // Get the DIBSection's color table
  564.         GetDIBColorTable( hMemDC, 0, 256, rgb );
  565.         // Create a palette from the color tabl
  566.         pLogPal = (LOGPALETTE *)malloc( sizeof(LOGPALETTE) + (256*sizeof(PALETTEENTRY)) );
  567.         pLogPal->palVersion = 0x300;
  568.         pLogPal->palNumEntries = 256;
  569.         for(i=0;i<256;i++)
  570.         {
  571.             pLogPal->palPalEntry[i].peRed = rgb[i].rgbRed;
  572.             pLogPal->palPalEntry[i].peGreen = rgb[i].rgbGreen;
  573.             pLogPal->palPalEntry[i].peBlue = rgb[i].rgbBlue;
  574.             pLogPal->palPalEntry[i].peFlags = 0;
  575.         }
  576.         *phPalette = CreatePalette( pLogPal );
  577.         // Clean up
  578.         free( pLogPal );
  579.         SelectObject( hMemDC, hOldBitmap );
  580.         DeleteDC( hMemDC );
  581.     }
  582.     else   
  583.     {
  584.         // It has no color table, so use a halftone palette
  585.         HDC    hRefDC;       
  586.         hRefDC = GetDC( NULL );
  587.         *phPalette = CreateHalftonePalette( hRefDC );
  588.         ReleaseDC( NULL, hRefDC );
  589.     }
  590.  
  591.     return TRUE;   
  592.  
  593.  
  594.  
  595. //-----------------------------------------------------------------------------
  596. // Name: CreateAudioPathFromFile()
  597. // Desc: 
  598. //-----------------------------------------------------------------------------
  599. HRESULT CreateAudioPathFromFile( IDirectMusicAudioPath8** ppAudioPath, TCHAR* strFileName )
  600. {
  601.     HRESULT               hr;
  602.     IDirectMusicSegment8* pSegment = NULL;
  603.     IUnknown*             pUnknown = NULL;
  604.  
  605.     // DMusic only takes wide strings
  606.     WCHAR wstrFileName[MAX_PATH];
  607.     DXUtil_ConvertGenericStringToWide( wstrFileName, strFileName );
  608.  
  609.     IDirectMusicLoader8* pLoader = g_pMusicManager->GetLoader();
  610.  
  611.     if ( FAILED( hr = pLoader->LoadObjectFromFile( CLSID_DirectMusicAudioPathConfig,
  612.                                                    IID_IUnknown,
  613.                                                    wstrFileName,
  614.                                                    (LPVOID*) &pUnknown ) ) )
  615.     {
  616.         if( hr == DMUS_E_LOADER_FAILEDOPEN )
  617.             return hr;
  618.         return DXTRACE_ERR( TEXT("LoadObjectFromFile"), hr );
  619.     }
  620.  
  621.     IDirectMusicPerformance8* pPerformance = g_pMusicManager->GetPerformance();
  622.  
  623.     if( FAILED( hr = pPerformance->CreateAudioPath( pUnknown, TRUE, ppAudioPath ) ) )
  624.         return DXTRACE_ERR( TEXT("CreateAudioPath"), hr );
  625.  
  626.     return S_OK;
  627. }
  628.  
  629.  
  630.  
  631.  
  632.